package com.kcsj.demo.Controller;


import com.kcsj.demo.Mapper.ListMapper;
import com.kcsj.demo.Module.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
public class ListController {
    @Autowired
    ListMapper listMapper;
    @GetMapping("/list")
    public String listController(Map<String,Object> map){
        map.put("list",listMapper.list());
        Date date = new Date(listMapper.list().get(1).getGmtCreate());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        System.out.println(sdf.format(date));
        map.put("time",sdf.format(date));
        return "list";
    }
    @PostMapping("/del")
    public String delete(@RequestParam(name = "delete") String del) {
        listMapper.delete(del);
        return "jump";
    }
    @PostMapping("/mainInsert")
    public String commit(@RequestParam(name = "user_name") String userName,
                         @RequestParam(name = "supplier_name") String supplierName,
                         @RequestParam(name = "commodity_name") String commodityName,
                         @RequestParam(name = "commodity_number") String commodityNumber){
        Main main = new Main();
        main.setUserName(userName);
        main.setSupplierName(supplierName);
        main.setCommodityName(commodityName);
        main.setCommodityNumber(commodityNumber);
        main.setGmtCreate(System.currentTimeMillis());
        listMapper.insert(main);
        return "jump";
    }
}
